package com.atguigu.gmall.search.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.search.entiy.Goods;
import com.atguigu.gmall.search.service.SearchBizService;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:ahang
 * @create:2022-10-13 0:18
 * @Description:
 */
@RequestMapping("/api/inner/search")
@RestController
public class SearchController {

    @Autowired
    SearchBizService searchBizService;

    /**
     * 更新热度分
     * @param skuId
     * @param hotScore
     * @return
     */
    @GetMapping("/hotscore/{skuId}/{hotScore}")
    public Result updateHotScore(@PathVariable("skuId") Long skuId,@PathVariable("hotScore") Long hotScore){
        searchBizService.updateHotScore(skuId,hotScore);
        return Result.ok();
    }

    /**
     * 远程调用检索,将带的请求参数封装成json字符串
     * @param paramVo
     * @return
     */
    @PostMapping("/sku/search")
    public Result<SearchResponseVo> search(@RequestBody SearchParamVo paramVo){

        SearchResponseVo responseVo = searchBizService.search(paramVo);
        return Result.ok(responseVo);
    }


    /**
     * 商品保存到es中
     * @param goods
     * @return
     */
    @PostMapping("/onsale")
    public Result onSaleGoods(@RequestBody Goods goods){
        searchBizService.onSale(goods);
        return Result.ok();
    }

    /**
     * 从es中删除商品
     * @param skuId
     * @return
     */
    @DeleteMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        searchBizService.cancelSale(skuId);
        return Result.ok();
    }


}
